package com.xszx.business.controller.web;

import com.xszx.server.dto.AjaxJson;
import com.xszx.server.dto.Page;
import com.xszx.server.service.CourseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("webCourseController")
@RequestMapping("/web/course")
public class CourseController {

    private static final Logger LOG = LoggerFactory.getLogger(CourseController.class);
    public static final String BUSINESS_NAME = "课程";

    @Resource
    private CourseService courseService;

    /**
     * 列表查询，查询最新的5门已发布的课程
     */
    @GetMapping("/list-new")
    public AjaxJson listNew(){
        Page page = new Page();
        page.setPage(1);
        page.setSize(5);
        return AjaxJson.success().put("page",courseService.getAllCourses(page)) ;
    }

    /**
     * 列表查询
     */
    @PostMapping("/getAllCourses")
    public AjaxJson getAllCourses(@RequestBody Page page){
        return AjaxJson.success().put("page",courseService.getAllCourses(page));
    }


    @GetMapping("/getCourse/{id}")
    public AjaxJson getCourse(@PathVariable String id){
        return AjaxJson.success().put("course",courseService.getCourse(id));
    }

}
